<template>
  <div class="balance-log-con">
    <div class="table">
      <div class="thead">
        <div class="tr">
          <div class="td">类型</div>
          <div class="td">时间</div>
        </div>
      </div>
      <div class="tbody"
           v-if="balanceLog.length>0">
        <van-list v-model="loading"
                  :finished="finished"
                  :error.sync="error"
                  error-text="请求失败，点击重新加载"
                  finished-text=""
                  @load="onLoad">
          <div class="tr log-tr"
               v-for="(balanceItem,index) in balanceLog"
               :key="index">
            <div class="td">
              <div class="remark">当前余额：{{ balanceItem.balance }}</div>
              <div class="time">{{ balanceItem.createDate }}</div>
            </div>
            <div class="td">
              <div class="remark">{{ balanceItem.businessDesc }}</div>

            </div>
          </div>
        </van-list>
      </div>
      <div v-else>
        <no-data :noData="noData"></no-data>
      </div>
    </div>
  </div>
</template>

<script>
import noData from '@/components/noData/index'
import { getbjhBalanceList } from '@/api/dz/dzApi'

export default {
  name: 'index',
  components: {
    noData
  },
  created() {
    this.init()
  },
  data() {
    return {
      noData: {
        width: '49%',
        txtMarginTop: '-30px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无数据'
      },
      page: 1,
      balanceLog: [],
      error: false,
      loading: false,
      finished: false
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      this.page = 1
      this.balanceLog = []
      this.onLoad()
    },
    onLoad() {
      const params = {
        p: this.page
      }
      getbjhBalanceList(params)
        .then((res) => {
          this.loading = false
          this.$loadingWrap.close()
          // eslint-disable-next-line radix
          const status = parseInt(res.status)
          if (status === 1) {
            // console.log('res------->', res)
            // console.log('res.data------->', res.data)
            // console.log('res.data.list------->', res.data.list)
            // console.log('res.data.length------->', res.data.length)
            if (res.status == 1 && res.data !== undefined && res.data.list !== undefined && res.data.list.length) {
              const resData = res.data
              this.balanceLog.push(...resData.list)
              // console.log(this.balanceLog)
              if (resData.list.length < 10) {
                this.finished = true
              } else {
                this.page++
              }
            } else {
              this.$Error(res.msg)
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
    }
  }
}
</script>

<style lang="scss">
.balance-log-con {
  margin-top: 30px;
  // margin: 0 20px;
  text-align: center;

  .tr {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    align-items: center;
    border-bottom: 2px solid #EEEEEE;
    padding: 0 24px;

    &:last-child {
      border-bottom: 0;
    }

    .td {
      // flex-basis: 33.3333%;
      // flex-basis: 1;
      &:nth-child(1) {
        flex: 1;
        text-align: left;
      }

      &:nth-child(2) {
        width: 50%;
        text-align: right;
      }

      // &:nth-child(2) {
      //   flex: 1;
      // }
      // &:nth-child(3) {
      //   flex: 2;
      // }
      &.no-data {
        color: #666;
      }
    }
  }

  .thead {
    border-radius: 10px;
    background: #F8F8F8;
    line-height: 86px;

    .td {
      font-size: 24px;
      font-weight: bold;
      color: #333333;
    }
  }

  .tbody {
    .td {
      line-height: 1.6;
      padding: 30px 0;

      .remark {
        font-size: 28px;
        font-weight: bold;
      }

      .time {
        color: #999;
      }
    }
  }
}
</style>
